/*
Compare differences in group-specific estimates for race and ethnicity
White-Black 
White-Indian/Native Alaskan
White-Hispanic
*/

// Make empty files for putting results in later

clear all
gen str32 vble = ""
foreach v in d_empt_tau0tau6 d_empt_tau1tau6 d_empt_pre1pre6 d_empt_pre3pre6 ///
	d_empt_tau0 d_empt_tau1 d_empt_tau2 d_empt_tau3 d_empt_tau4 ///
	d_empt_tau5 d_empt_tau6 d_empt_d_ATT  ///
	d_wgt_tau0tau6 d_wgt_tau1tau6 d_wgt_pre1pre6 d_wgt_pre3pre6 ///
	d_wgt_tau0 d_wgt_tau1 d_wgt_tau2 d_wgt_tau3 d_wgt_tau4 ///
	d_wgt_tau5 d_wgt_tau6 d_wgt_d_ATT  ///
	d_empc_tau0tau6 d_empc_tau1tau6 d_empc_pre1pre6 d_empc_pre3pre6 ///
	d_empc_tau0 d_empc_tau1 d_empc_tau2 d_empc_tau3 d_empc_tau4 ///
	d_empc_tau5 d_empc_tau6 d_empc_d_ATT  ///
	d_wgc_tau0tau6 d_wgc_tau1tau6 d_wgc_pre1pre6 d_wgc_pre3pre6 ///
	d_wgc_tau0 d_wgc_tau1 d_wgc_tau2 d_wgc_tau3 d_wgc_tau4 ///
	d_wgc_tau5 d_wgc_tau6 d_wgc_d_ATT {
	gen double `v' = .
}

drop if _n>0


save "/projects/users/########/Snapshot2022/Results/whtblack_compare.dta", replace
save "/projects/users/########/Snapshot2022/Results/whthisp_compare.dta", replace
save "/projects/users/########/Snapshot2022/Results/whtindnat_compare.dta", replace
/*
save "/projects/users/########/Snapshot2022/Results/whtblack_compare_nvbig.dta", replace
save "/projects/users/########/Snapshot2022/Results/whthisp_compare_nvbig.dta", replace
save "/projects/users/########/Snapshot2022/Results/whtindnat_compare_nvbig.dta", replace
*/

************************************
* White-Black Comparison
************************************

// Read and organize data from each race/ethnicity

clear all
use "/projects/users/########/Snapshot2022/Results/lpdid2_strateq2_white2.dta"
*use "/projects/users/########/Snapshot2022/Results/lpdid_strateq_white_nvbig.dta", clear

keep vble b_*
rename b_emp20bscpl0 b_empt_wht
rename b_emp20cbscpl0 b_empc_wht
rename b_wg20bscpl0 b_wgt_wht
rename b_wg20cbscpl0 b_wgc_wht
gen index = _n

tempfile wht_estimates
save `wht_estimates'

use "/projects/users/########/Snapshot2022/Results/lpdid2_strateq2_black2.dta", clear
*use "/projects/users/########/Snapshot2022/Results/lpdid_strateq_black_nvbig.dta", clear

keep vble b_*
rename b_emp20bscpl0 b_empt_black
rename b_emp20cbscpl0 b_empc_black
rename b_wg20bscpl0 b_wgt_black
rename b_wg20cbscpl0 b_wgc_black
gen index = _n

merge 1:1 index using `wht_estimates'
keep if _merge==3

gen d_empt = b_empt_wht - b_empt_black
gen d_wgt = b_wgt_wht - b_wgt_black
gen d_empc = b_empc_wht - b_empc_black
gen d_wgc = b_wgc_wht - b_wgc_black

// Create tempfile to hold results of comparisons

capture postutil clear
tempfile wht_black
postfile handle str32 vble double ///
	d_empt_tau0tau6 d_empt_tau1tau6 d_empt_pre1pre6 d_empt_pre3pre6 ///
	d_empt_tau0 d_empt_tau1 d_empt_tau2 d_empt_tau3 d_empt_tau4 ///
	d_empt_tau5 d_empt_tau6 d_empt_d_ATT  ///
	d_wgt_tau0tau6 d_wgt_tau1tau6 d_wgt_pre1pre6 d_wgt_pre3pre6 ///
	d_wgt_tau0 d_wgt_tau1 d_wgt_tau2 d_wgt_tau3 d_wgt_tau4 ///
	d_wgt_tau5 d_wgt_tau6 d_wgt_d_ATT  ///
	d_empc_tau0tau6 d_empc_tau1tau6 d_empc_pre1pre6 d_empc_pre3pre6 ///
	d_empc_tau0 d_empc_tau1 d_empc_tau2 d_empc_tau3 d_empc_tau4 ///
	d_empc_tau5 d_empc_tau6 d_empc_d_ATT  ///
	d_wgc_tau0tau6 d_wgc_tau1tau6 d_wgc_pre1pre6 d_wgc_pre3pre6 ///
	d_wgc_tau0 d_wgc_tau1 d_wgc_tau2 d_wgc_tau3 d_wgc_tau4 ///
	d_wgc_tau5 d_wgc_tau6 d_wgc_d_ATT  ///
	using `wht_black', replace
	
// Calculate comparisons and store in a matrix

foreach var of varlist d_empt d_wgt d_empc d_wgc {
	matrix comps = J(12,4,.)
	matrix colnames comps = Num MeanDiff PctPos PctNeg
	
	summ `var' if inlist(vble,"tau0","tau1","tau2","tau3","tau4","tau5","tau6"), det
	matrix comps[1,1] = r(N)
	matrix comps[1,2] = r(mean)
	summ `var' if inlist(vble,"tau0","tau1","tau2","tau3","tau4","tau5","tau6") & `var'>0
	matrix comps[1,3] = r(N)/comps[1,1]
	summ `var' if inlist(vble,"tau0","tau1","tau2","tau3","tau4","tau5","tau6") & `var'<0
	matrix comps[1,4] = r(N)/comps[1,1]
	
	summ `var' if inlist(vble,"tau1","tau2","tau3","tau4","tau5","tau6"), det
	matrix comps[2,1] = r(N)
	matrix comps[2,2] = r(mean)
	summ `var' if inlist(vble,"tau1","tau2","tau3","tau4","tau5","tau6") & `var'>0
	matrix comps[2,3] = r(N)/comps[2,1]
	summ `var' if inlist(vble,"tau1","tau2","tau3","tau4","tau5","tau6") & `var'<0
	matrix comps[2,4] = r(N)/comps[2,1]	
	
	summ `var' if inlist(vble,"pre1","pre3","pre4","pre5","pre6"), det
	matrix comps[3,1] = r(N)
	matrix comps[3,2] = r(mean)
	summ `var' if inlist(vble,"pre1","pre3","pre4","pre5","pre6") & `var'>0
	matrix comps[3,3] = r(N)/comps[3,1]
	summ `var' if inlist(vble,"pre1","pre3","pre4","pre5","pre6") & `var'<0
	matrix comps[3,4] = r(N)/comps[3,1]

	summ `var' if inlist(vble,"pre3","pre4","pre5","pre6"), det
	matrix comps[4,1] = r(N)
	matrix comps[4,2] = r(mean)
	summ `var' if inlist(vble,"pre3","pre4","pre5","pre6") & `var'>0
	matrix comps[4,3] = r(N)/comps[4,1]
	summ `var' if inlist(vble,"pre3","pre4","pre5","pre6") & `var'<0
	matrix comps[4,4] = r(N)/comps[4,1]
	
	foreach num of numlist 0/6 {
		summ `var' if inlist(vble,"tau`num'"), det
		matrix comps[5+`num',1] = r(N)
		matrix comps[5+`num',2] = r(mean)
		summ `var' if inlist(vble,"tau`num'") & `var'>0
		matrix comps[5+`num',3] = r(N)/comps[5+`num',1]
		summ `var' if inlist(vble,"tau`num'") & `var'<0
		matrix comps[5+`num',4] = r(N)/comps[5+`num',1]
	}
	
	matrix rownames comps = ///
		`var'_tau0tau6 `var'_tau1tau6 `var'_pre1pre6 `var'_pre3pre6 ///
		`var'_tau0 `var'_tau1 `var'_tau2 `var'_tau3 `var'_tau4 ///
		`var'_tau5 `var'_tau6 `var'_d_ATT 
		
	matrix whtblack_`var' = (comps)
	matrix drop comps
}

// Export the matrix values to the temp file and save a permanent file

foreach v in Num MeanDiff PctPos PctNeg {
	post handle ("`v'") ///
	(whtblack_d_empt["d_empt_tau0tau6", "`v'"]) ///
	(whtblack_d_empt["d_empt_tau1tau6", "`v'"]) ///
	(whtblack_d_empt["d_empt_pre1pre6", "`v'"]) ///
	(whtblack_d_empt["d_empt_pre3pre6", "`v'"]) ///
	(whtblack_d_empt["d_empt_tau0", "`v'"]) (whtblack_d_empt["d_empt_tau1", "`v'"]) ///
	(whtblack_d_empt["d_empt_tau2", "`v'"]) (whtblack_d_empt["d_empt_tau3", "`v'"]) ///
	(whtblack_d_empt["d_empt_tau4", "`v'"]) (whtblack_d_empt["d_empt_tau5", "`v'"]) ///
	(whtblack_d_empt["d_empt_tau6", "`v'"]) (whtblack_d_empt["d_empt_d_ATT", "`v'"]) ///
	(whtblack_d_wgt["d_wgt_tau0tau6", "`v'"]) ///
	(whtblack_d_wgt["d_wgt_tau1tau6", "`v'"]) ///
	(whtblack_d_wgt["d_wgt_pre1pre6", "`v'"]) ///
	(whtblack_d_wgt["d_wgt_pre3pre6", "`v'"]) ///
	(whtblack_d_wgt["d_wgt_tau0", "`v'"]) (whtblack_d_wgt["d_wgt_tau1", "`v'"]) ///
	(whtblack_d_wgt["d_wgt_tau2", "`v'"]) (whtblack_d_wgt["d_wgt_tau3", "`v'"]) ///
	(whtblack_d_wgt["d_wgt_tau4", "`v'"]) (whtblack_d_wgt["d_wgt_tau5", "`v'"]) ///
	(whtblack_d_wgt["d_wgt_tau6", "`v'"]) (whtblack_d_wgt["d_wgt_d_ATT", "`v'"]) ///
	(whtblack_d_empc["d_empc_tau0tau6", "`v'"]) ///
	(whtblack_d_empc["d_empc_tau1tau6", "`v'"]) ///
	(whtblack_d_empc["d_empc_pre1pre6", "`v'"]) ///
	(whtblack_d_empc["d_empc_pre3pre6", "`v'"]) ///
	(whtblack_d_empc["d_empc_tau0", "`v'"]) (whtblack_d_empc["d_empc_tau1", "`v'"]) ///
	(whtblack_d_empc["d_empc_tau2", "`v'"]) (whtblack_d_empc["d_empc_tau3", "`v'"]) ///
	(whtblack_d_empc["d_empc_tau4", "`v'"]) (whtblack_d_empc["d_empc_tau5", "`v'"]) ///
	(whtblack_d_empc["d_empc_tau6", "`v'"]) (whtblack_d_empc["d_empc_d_ATT", "`v'"]) ///
	(whtblack_d_wgc["d_wgc_tau0tau6", "`v'"]) ///
	(whtblack_d_wgc["d_wgc_tau1tau6", "`v'"]) ///
	(whtblack_d_wgc["d_wgc_pre1pre6", "`v'"]) ///
	(whtblack_d_wgc["d_wgc_pre3pre6", "`v'"]) ///
	(whtblack_d_wgc["d_wgc_tau0", "`v'"]) (whtblack_d_wgc["d_wgc_tau1", "`v'"]) ///
	(whtblack_d_wgc["d_wgc_tau2", "`v'"]) (whtblack_d_wgc["d_wgc_tau3", "`v'"]) ///
	(whtblack_d_wgc["d_wgc_tau4", "`v'"]) (whtblack_d_wgc["d_wgc_tau5", "`v'"]) ///
	(whtblack_d_wgc["d_wgc_tau6", "`v'"]) (whtblack_d_wgc["d_wgc_d_ATT", "`v'"]) 
}

postclose handle
preserve
use "/projects/users/########/Snapshot2022/Results/whtblack_compare.dta", clear
*use "/projects/users/########/Snapshot2022/Results/whtblack_compare_nvbig.dta", clear
append using `wht_black'
save "/projects/users/########/Snapshot2022/Results/whtblack_compare.dta", replace
*save "/projects/users/########/Snapshot2022/Results/whtblack_compare_nvbig.dta", replace
restore

************************************
* White-Hispanic Comparison
************************************

// Read and organize data from each race/ethnicity

clear all
use "/projects/users/########/Snapshot2022/Results/lpdid2_strateq2_white2.dta"

keep vble b_*
rename b_emp20bscpl0 b_empt_wht
rename b_emp20cbscpl0 b_empc_wht
rename b_wg20bscpl0 b_wgt_wht
rename b_wg20cbscpl0 b_wgc_wht
gen index = _n

tempfile wht_estimates
save `wht_estimates'

use "/projects/users/########/Snapshot2022/Results/lpdid2_strateq2_hisp2.dta", clear

keep vble b_*
rename b_emp20bscpl0 b_empt_hisp
rename b_emp20cbscpl0 b_empc_hisp
rename b_wg20bscpl0 b_wgt_hisp
rename b_wg20cbscpl0 b_wgc_hisp
gen index = _n

merge 1:1 index using `wht_estimates'
keep if _merge==3

gen d_empt = b_empt_wht - b_empt_hisp
gen d_wgt = b_wgt_wht - b_wgt_hisp
gen d_empc = b_empc_wht - b_empc_hisp
gen d_wgc = b_wgc_wht - b_wgc_hisp

// Create tempfile to hold results of comparisons

capture postutil clear
tempfile wht_hisp
postfile handle str32 vble double ///
	d_empt_tau0tau6 d_empt_tau1tau6 d_empt_pre1pre6 d_empt_pre3pre6 ///
	d_empt_tau0 d_empt_tau1 d_empt_tau2 d_empt_tau3 d_empt_tau4 ///
	d_empt_tau5 d_empt_tau6 d_empt_d_ATT  ///
	d_wgt_tau0tau6 d_wgt_tau1tau6 d_wgt_pre1pre6 d_wgt_pre3pre6 ///
	d_wgt_tau0 d_wgt_tau1 d_wgt_tau2 d_wgt_tau3 d_wgt_tau4 ///
	d_wgt_tau5 d_wgt_tau6 d_wgt_d_ATT  ///
	d_empc_tau0tau6 d_empc_tau1tau6 d_empc_pre1pre6 d_empc_pre3pre6 ///
	d_empc_tau0 d_empc_tau1 d_empc_tau2 d_empc_tau3 d_empc_tau4 ///
	d_empc_tau5 d_empc_tau6 d_empc_d_ATT  ///
	d_wgc_tau0tau6 d_wgc_tau1tau6 d_wgc_pre1pre6 d_wgc_pre3pre6 ///
	d_wgc_tau0 d_wgc_tau1 d_wgc_tau2 d_wgc_tau3 d_wgc_tau4 ///
	d_wgc_tau5 d_wgc_tau6 d_wgc_d_ATT  ///
	using `wht_hisp', replace
	
// Calculate comparisons and store in a matrix

foreach var of varlist d_empt d_wgt d_empc d_wgc {
	matrix comps = J(12,4,.)
	matrix colnames comps = Num MeanDiff PctPos PctNeg
	
	summ `var' if inlist(vble,"tau0","tau1","tau2","tau3","tau4","tau5","tau6"), det
	matrix comps[1,1] = r(N)
	matrix comps[1,2] = r(mean)
	summ `var' if inlist(vble,"tau0","tau1","tau2","tau3","tau4","tau5","tau6") & `var'>0
	matrix comps[1,3] = r(N)/comps[1,1]
	summ `var' if inlist(vble,"tau0","tau1","tau2","tau3","tau4","tau5","tau6") & `var'<0
	matrix comps[1,4] = r(N)/comps[1,1]
	
	summ `var' if inlist(vble,"tau1","tau2","tau3","tau4","tau5","tau6"), det
	matrix comps[2,1] = r(N)
	matrix comps[2,2] = r(mean)
	summ `var' if inlist(vble,"tau1","tau2","tau3","tau4","tau5","tau6") & `var'>0
	matrix comps[2,3] = r(N)/comps[2,1]
	summ `var' if inlist(vble,"tau1","tau2","tau3","tau4","tau5","tau6") & `var'<0
	matrix comps[2,4] = r(N)/comps[2,1]	
	
	summ `var' if inlist(vble,"pre1","pre3","pre4","pre5","pre6"), det
	matrix comps[3,1] = r(N)
	matrix comps[3,2] = r(mean)
	summ `var' if inlist(vble,"pre1","pre3","pre4","pre5","pre6") & `var'>0
	matrix comps[3,3] = r(N)/comps[3,1]
	summ `var' if inlist(vble,"pre1","pre3","pre4","pre5","pre6") & `var'<0
	matrix comps[3,4] = r(N)/comps[3,1]

	summ `var' if inlist(vble,"pre3","pre4","pre5","pre6"), det
	matrix comps[4,1] = r(N)
	matrix comps[4,2] = r(mean)
	summ `var' if inlist(vble,"pre3","pre4","pre5","pre6") & `var'>0
	matrix comps[4,3] = r(N)/comps[4,1]
	summ `var' if inlist(vble,"pre3","pre4","pre5","pre6") & `var'<0
	matrix comps[4,4] = r(N)/comps[4,1]
	
	foreach num of numlist 0/6 {
		summ `var' if inlist(vble,"tau`num'"), det
		matrix comps[5+`num',1] = r(N)
		matrix comps[5+`num',2] = r(mean)
		summ `var' if inlist(vble,"tau`num'") & `var'>0
		matrix comps[5+`num',3] = r(N)/comps[5+`num',1]
		summ `var' if inlist(vble,"tau`num'") & `var'<0
		matrix comps[5+`num',4] = r(N)/comps[5+`num',1]
	}
	
	matrix rownames comps = ///
		`var'_tau0tau6 `var'_tau1tau6 `var'_pre1pre6 `var'_pre3pre6 ///
		`var'_tau0 `var'_tau1 `var'_tau2 `var'_tau3 `var'_tau4 ///
		`var'_tau5 `var'_tau6 `var'_d_ATT 
		
	matrix whthisp_`var' = (comps)
	matrix drop comps
}

// Export the matrix values to the temp file and save a permanent file

foreach v in Num MeanDiff PctPos PctNeg {
	post handle ("`v'") ///
	(whthisp_d_empt["d_empt_tau0tau6", "`v'"]) ///
	(whthisp_d_empt["d_empt_tau1tau6", "`v'"]) ///
	(whthisp_d_empt["d_empt_pre1pre6", "`v'"]) ///
	(whthisp_d_empt["d_empt_pre3pre6", "`v'"]) ///
	(whthisp_d_empt["d_empt_tau0", "`v'"]) (whthisp_d_empt["d_empt_tau1", "`v'"]) ///
	(whthisp_d_empt["d_empt_tau2", "`v'"]) (whthisp_d_empt["d_empt_tau3", "`v'"]) ///
	(whthisp_d_empt["d_empt_tau4", "`v'"]) (whthisp_d_empt["d_empt_tau5", "`v'"]) ///
	(whthisp_d_empt["d_empt_tau6", "`v'"]) (whthisp_d_empt["d_empt_d_ATT", "`v'"]) ///
	(whthisp_d_wgt["d_wgt_tau0tau6", "`v'"]) ///
	(whthisp_d_wgt["d_wgt_tau1tau6", "`v'"]) ///
	(whthisp_d_wgt["d_wgt_pre1pre6", "`v'"]) ///
	(whthisp_d_wgt["d_wgt_pre3pre6", "`v'"]) ///
	(whthisp_d_wgt["d_wgt_tau0", "`v'"]) (whthisp_d_wgt["d_wgt_tau1", "`v'"]) ///
	(whthisp_d_wgt["d_wgt_tau2", "`v'"]) (whthisp_d_wgt["d_wgt_tau3", "`v'"]) ///
	(whthisp_d_wgt["d_wgt_tau4", "`v'"]) (whthisp_d_wgt["d_wgt_tau5", "`v'"]) ///
	(whthisp_d_wgt["d_wgt_tau6", "`v'"]) (whthisp_d_wgt["d_wgt_d_ATT", "`v'"]) ///
	(whthisp_d_empc["d_empc_tau0tau6", "`v'"]) ///
	(whthisp_d_empc["d_empc_tau1tau6", "`v'"]) ///
	(whthisp_d_empc["d_empc_pre1pre6", "`v'"]) ///
	(whthisp_d_empc["d_empc_pre3pre6", "`v'"]) ///
	(whthisp_d_empc["d_empc_tau0", "`v'"]) (whthisp_d_empc["d_empc_tau1", "`v'"]) ///
	(whthisp_d_empc["d_empc_tau2", "`v'"]) (whthisp_d_empc["d_empc_tau3", "`v'"]) ///
	(whthisp_d_empc["d_empc_tau4", "`v'"]) (whthisp_d_empc["d_empc_tau5", "`v'"]) ///
	(whthisp_d_empc["d_empc_tau6", "`v'"]) (whthisp_d_empc["d_empc_d_ATT", "`v'"]) ///
	(whthisp_d_wgc["d_wgc_tau0tau6", "`v'"]) ///
	(whthisp_d_wgc["d_wgc_tau1tau6", "`v'"]) ///
	(whthisp_d_wgc["d_wgc_pre1pre6", "`v'"]) ///
	(whthisp_d_wgc["d_wgc_pre3pre6", "`v'"]) ///
	(whthisp_d_wgc["d_wgc_tau0", "`v'"]) (whthisp_d_wgc["d_wgc_tau1", "`v'"]) ///
	(whthisp_d_wgc["d_wgc_tau2", "`v'"]) (whthisp_d_wgc["d_wgc_tau3", "`v'"]) ///
	(whthisp_d_wgc["d_wgc_tau4", "`v'"]) (whthisp_d_wgc["d_wgc_tau5", "`v'"]) ///
	(whthisp_d_wgc["d_wgc_tau6", "`v'"]) (whthisp_d_wgc["d_wgc_d_ATT", "`v'"]) 
}

postclose handle
preserve
use "/projects/users/########/Snapshot2022/Results/whthisp_compare.dta", clear
append using `wht_hisp'
save "/projects/users/########/Snapshot2022/Results/whthisp_compare.dta", replace
restore

************************************
* White-Indian/Native Alaskan Comparison
************************************

// Read and organize data from each race/ethnicity

clear all
use "/projects/users/########/Snapshot2022/Results/lpdid2_strateq2_white2.dta"

keep vble b_*
rename b_emp20bscpl0 b_empt_wht
rename b_emp20cbscpl0 b_empc_wht
rename b_wg20bscpl0 b_wgt_wht
rename b_wg20cbscpl0 b_wgc_wht
gen index = _n

tempfile wht_estimates
save `wht_estimates'

use "/projects/users/########/Snapshot2022/Results/lpdid2_strateq2_indnat2.dta", clear

keep vble b_*
rename b_emp20bscpl0 b_empt_indnat
rename b_emp20cbscpl0 b_empc_indnat
rename b_wg20bscpl0 b_wgt_indnat
rename b_wg20cbscpl0 b_wgc_indnat
gen index = _n

merge 1:1 index using `wht_estimates'
keep if _merge==3

gen d_empt = b_empt_wht - b_empt_indnat
gen d_wgt = b_wgt_wht - b_wgt_indnat
gen d_empc = b_empc_wht - b_empc_indnat
gen d_wgc = b_wgc_wht - b_wgc_indnat

// Create tempfile to hold results of comparisons

capture postutil clear
tempfile wht_indnat
postfile handle str32 vble double ///
	d_empt_tau0tau6 d_empt_tau1tau6 d_empt_pre1pre6 d_empt_pre3pre6 ///
	d_empt_tau0 d_empt_tau1 d_empt_tau2 d_empt_tau3 d_empt_tau4 ///
	d_empt_tau5 d_empt_tau6 d_empt_d_ATT  ///
	d_wgt_tau0tau6 d_wgt_tau1tau6 d_wgt_pre1pre6 d_wgt_pre3pre6 ///
	d_wgt_tau0 d_wgt_tau1 d_wgt_tau2 d_wgt_tau3 d_wgt_tau4 ///
	d_wgt_tau5 d_wgt_tau6 d_wgt_d_ATT  ///
	d_empc_tau0tau6 d_empc_tau1tau6 d_empc_pre1pre6 d_empc_pre3pre6 ///
	d_empc_tau0 d_empc_tau1 d_empc_tau2 d_empc_tau3 d_empc_tau4 ///
	d_empc_tau5 d_empc_tau6 d_empc_d_ATT  ///
	d_wgc_tau0tau6 d_wgc_tau1tau6 d_wgc_pre1pre6 d_wgc_pre3pre6 ///
	d_wgc_tau0 d_wgc_tau1 d_wgc_tau2 d_wgc_tau3 d_wgc_tau4 ///
	d_wgc_tau5 d_wgc_tau6 d_wgc_d_ATT  ///
	using `wht_indnat', replace
	
// Calculate comparisons and store in a matrix

foreach var of varlist d_empt d_wgt d_empc d_wgc {
	matrix comps = J(12,4,.)
	matrix colnames comps = Num MeanDiff PctPos PctNeg
	
	summ `var' if inlist(vble,"tau0","tau1","tau2","tau3","tau4","tau5","tau6"), det
	matrix comps[1,1] = r(N)
	matrix comps[1,2] = r(mean)
	summ `var' if inlist(vble,"tau0","tau1","tau2","tau3","tau4","tau5","tau6") & `var'>0
	matrix comps[1,3] = r(N)/comps[1,1]
	summ `var' if inlist(vble,"tau0","tau1","tau2","tau3","tau4","tau5","tau6") & `var'<0
	matrix comps[1,4] = r(N)/comps[1,1]
	
	summ `var' if inlist(vble,"tau1","tau2","tau3","tau4","tau5","tau6"), det
	matrix comps[2,1] = r(N)
	matrix comps[2,2] = r(mean)
	summ `var' if inlist(vble,"tau1","tau2","tau3","tau4","tau5","tau6") & `var'>0
	matrix comps[2,3] = r(N)/comps[2,1]
	summ `var' if inlist(vble,"tau1","tau2","tau3","tau4","tau5","tau6") & `var'<0
	matrix comps[2,4] = r(N)/comps[2,1]	
	
	summ `var' if inlist(vble,"pre1","pre3","pre4","pre5","pre6"), det
	matrix comps[3,1] = r(N)
	matrix comps[3,2] = r(mean)
	summ `var' if inlist(vble,"pre1","pre3","pre4","pre5","pre6") & `var'>0
	matrix comps[3,3] = r(N)/comps[3,1]
	summ `var' if inlist(vble,"pre1","pre3","pre4","pre5","pre6") & `var'<0
	matrix comps[3,4] = r(N)/comps[3,1]

	summ `var' if inlist(vble,"pre3","pre4","pre5","pre6"), det
	matrix comps[4,1] = r(N)
	matrix comps[4,2] = r(mean)
	summ `var' if inlist(vble,"pre3","pre4","pre5","pre6") & `var'>0
	matrix comps[4,3] = r(N)/comps[4,1]
	summ `var' if inlist(vble,"pre3","pre4","pre5","pre6") & `var'<0
	matrix comps[4,4] = r(N)/comps[4,1]
	
	foreach num of numlist 0/6 {
		summ `var' if inlist(vble,"tau`num'"), det
		matrix comps[5+`num',1] = r(N)
		matrix comps[5+`num',2] = r(mean)
		summ `var' if inlist(vble,"tau`num'") & `var'>0
		matrix comps[5+`num',3] = r(N)/comps[5+`num',1]
		summ `var' if inlist(vble,"tau`num'") & `var'<0
		matrix comps[5+`num',4] = r(N)/comps[5+`num',1]
	}
	
	matrix rownames comps = ///
		`var'_tau0tau6 `var'_tau1tau6 `var'_pre1pre6 `var'_pre3pre6 ///
		`var'_tau0 `var'_tau1 `var'_tau2 `var'_tau3 `var'_tau4 ///
		`var'_tau5 `var'_tau6 `var'_d_ATT 
		
	matrix whtindnat_`var' = (comps)
	matrix drop comps
}

// Export the matrix values to the temp file and save a permanent file

foreach v in Num MeanDiff PctPos PctNeg {
	post handle ("`v'") ///
	(whtindnat_d_empt["d_empt_tau0tau6", "`v'"]) ///
	(whtindnat_d_empt["d_empt_tau1tau6", "`v'"]) ///
	(whtindnat_d_empt["d_empt_pre1pre6", "`v'"]) ///
	(whtindnat_d_empt["d_empt_pre3pre6", "`v'"]) ///
	(whtindnat_d_empt["d_empt_tau0", "`v'"]) (whtindnat_d_empt["d_empt_tau1", "`v'"]) ///
	(whtindnat_d_empt["d_empt_tau2", "`v'"]) (whtindnat_d_empt["d_empt_tau3", "`v'"]) ///
	(whtindnat_d_empt["d_empt_tau4", "`v'"]) (whtindnat_d_empt["d_empt_tau5", "`v'"]) ///
	(whtindnat_d_empt["d_empt_tau6", "`v'"]) (whtindnat_d_empt["d_empt_d_ATT", "`v'"]) ///
	(whtindnat_d_wgt["d_wgt_tau0tau6", "`v'"]) ///
	(whtindnat_d_wgt["d_wgt_tau1tau6", "`v'"]) ///
	(whtindnat_d_wgt["d_wgt_pre1pre6", "`v'"]) ///
	(whtindnat_d_wgt["d_wgt_pre3pre6", "`v'"]) ///
	(whtindnat_d_wgt["d_wgt_tau0", "`v'"]) (whtindnat_d_wgt["d_wgt_tau1", "`v'"]) ///
	(whtindnat_d_wgt["d_wgt_tau2", "`v'"]) (whtindnat_d_wgt["d_wgt_tau3", "`v'"]) ///
	(whtindnat_d_wgt["d_wgt_tau4", "`v'"]) (whtindnat_d_wgt["d_wgt_tau5", "`v'"]) ///
	(whtindnat_d_wgt["d_wgt_tau6", "`v'"]) (whtindnat_d_wgt["d_wgt_d_ATT", "`v'"]) ///
	(whtindnat_d_empc["d_empc_tau0tau6", "`v'"]) ///
	(whtindnat_d_empc["d_empc_tau1tau6", "`v'"]) ///
	(whtindnat_d_empc["d_empc_pre1pre6", "`v'"]) ///
	(whtindnat_d_empc["d_empc_pre3pre6", "`v'"]) ///
	(whtindnat_d_empc["d_empc_tau0", "`v'"]) (whtindnat_d_empc["d_empc_tau1", "`v'"]) ///
	(whtindnat_d_empc["d_empc_tau2", "`v'"]) (whtindnat_d_empc["d_empc_tau3", "`v'"]) ///
	(whtindnat_d_empc["d_empc_tau4", "`v'"]) (whtindnat_d_empc["d_empc_tau5", "`v'"]) ///
	(whtindnat_d_empc["d_empc_tau6", "`v'"]) (whtindnat_d_empc["d_empc_d_ATT", "`v'"]) ///
	(whtindnat_d_wgc["d_wgc_tau0tau6", "`v'"]) ///
	(whtindnat_d_wgc["d_wgc_tau1tau6", "`v'"]) ///
	(whtindnat_d_wgc["d_wgc_pre1pre6", "`v'"]) ///
	(whtindnat_d_wgc["d_wgc_pre3pre6", "`v'"]) ///
	(whtindnat_d_wgc["d_wgc_tau0", "`v'"]) (whtindnat_d_wgc["d_wgc_tau1", "`v'"]) ///
	(whtindnat_d_wgc["d_wgc_tau2", "`v'"]) (whtindnat_d_wgc["d_wgc_tau3", "`v'"]) ///
	(whtindnat_d_wgc["d_wgc_tau4", "`v'"]) (whtindnat_d_wgc["d_wgc_tau5", "`v'"]) ///
	(whtindnat_d_wgc["d_wgc_tau6", "`v'"]) (whtindnat_d_wgc["d_wgc_d_ATT", "`v'"]) 
}

postclose handle
preserve
use "/projects/users/########/Snapshot2022/Results/whtindnat_compare.dta", clear
append using `wht_indnat'
save "/projects/users/########/Snapshot2022/Results/whtindnat_compare.dta", replace
restore

/*
Histograms of differences

// Compare binary treatment on employment
hist d_empt if inlist(vble,"tau0","tau1","tau2","tau3","tau4","tau5","tau6")
hist d_empt if inlist(vble,"tau1","tau2","tau3","tau4","tau5","tau6")

hist d_empt if inlist(vble,"pre1","pre3","pre4","pre5","pre6")
hist d_empt if inlist(vble,"pre3","pre4","pre5","pre6")

hist d_empt if inlist(vble,"tau0")
hist d_empt if inlist(vble,"tau1")
hist d_empt if inlist(vble,"tau2")
hist d_empt if inlist(vble,"tau3")
hist d_empt if inlist(vble,"tau4")
hist d_empt if inlist(vble,"tau5")
hist d_empt if inlist(vble,"tau6")

// Compare binary treatment on earnings
hist d_wgt if inlist(vble,"tau0","tau1","tau2","tau3","tau4","tau5","tau6")
hist d_wgt if inlist(vble,"tau1","tau2","tau3","tau4","tau5","tau6")

hist d_wgt if inlist(vble,"pre1","pre3","pre4","pre5","pre6")
hist d_wgt if inlist(vble,"pre3","pre4","pre5","pre6")

hist d_wgt if inlist(vble,"tau0")
hist d_wgt if inlist(vble,"tau1")
hist d_wgt if inlist(vble,"tau2")
hist d_wgt if inlist(vble,"tau3")
hist d_wgt if inlist(vble,"tau4")
hist d_wgt if inlist(vble,"tau5")
hist d_wgt if inlist(vble,"tau6")

// Compare continuous treatment on employment
hist d_empc if inlist(vble,"tau0","tau1","tau2","tau3","tau4","tau5","tau6")
hist d_empc if inlist(vble,"tau1","tau2","tau3","tau4","tau5","tau6")

hist d_empc if inlist(vble,"pre1","pre3","pre4","pre5","pre6")
hist d_empc if inlist(vble,"pre3","pre4","pre5","pre6")

hist d_empc if inlist(vble,"tau0")
hist d_empc if inlist(vble,"tau1")
hist d_empc if inlist(vble,"tau2")
hist d_empc if inlist(vble,"tau3")
hist d_empc if inlist(vble,"tau4")
hist d_empc if inlist(vble,"tau5")
hist d_empc if inlist(vble,"tau6")

// Compare continuous treatment on earnings
hist d_wgc if inlist(vble,"tau0","tau1","tau2","tau3","tau4","tau5","tau6")
hist d_wgc if inlist(vble,"tau1","tau2","tau3","tau4","tau5","tau6")

hist d_wgc if inlist(vble,"pre1","pre3","pre4","pre5","pre6")
hist d_wgc if inlist(vble,"pre3","pre4","pre5","pre6")

hist d_wgc if inlist(vble,"tau0")
hist d_wgc if inlist(vble,"tau1")
hist d_wgc if inlist(vble,"tau2")
hist d_wgc if inlist(vble,"tau3")
hist d_wgc if inlist(vble,"tau4")
hist d_wgc if inlist(vble,"tau5")
hist d_wgc if inlist(vble,"tau6")
*/

/*
matrix whtblack = J(48,4,.)
matrix colnames whtblack = Num MeanDiff PctPos PctNeg
matrix rownames whtblack = ///
	et_tau0tau6 et_tau1tau6 et_pre1pre6 et_pre3pre6 ///
	et_tau0 et_tau1 et_tau2 et_tau3 et_tau4 et_tau5 et_tau6 et_ATTDiff ///
	wt_tau0tau6 wt_tau1tau6 wt_pre1pre6 wt_pre3pre6 ///
	wt_tau0 wt_tau1 wt_tau2 wt_tau3 wt_tau4 wt_tau5 wt_tau6 wt_ATTDiff ///
	ec_tau0tau6 ec_tau1tau6 ec_pre1pre6 ec_pre3pre6 ///
	ec_tau0 ec_tau1 ec_tau2 ec_tau3 ec_tau4 ec_tau5 ec_tau6 ec_ATTDiff ///
	wc_tau0tau6 wc_tau1tau6 wc_pre1pre6 wc_pre3pre6 ///
	wc_tau0 wc_tau1 wc_tau2 wc_tau3 wc_tau4 wc_tau5 wc_tau6 wc_ATTDiff 
	
	
hist d_empt if inlist(vble,"tau0")
summ d_empt if inlist(vble,"tau0"), det
matrix whtblack[5,1] = r(N)
matrix whtblack[5,2] = r(mean)
summ d_empt if inlist(vble,"tau0") & d_empt>0
matrix whtblack[5,3] = r(N)/whtblack[5,1]
summ d_empt if inlist(vble,"tau0") & d_empt<0
matrix whtblack[5,4] = r(N)/whtblack[5,1]
* 

hist d_empt if inlist(vble,"tau1")
summ d_empt if inlist(vble,"tau1"), det
matrix whtblack[6,1] = r(N)
matrix whtblack[6,2] = r(mean)
summ d_empt if inlist(vble,"tau1") & d_empt>0
matrix whtblack[6,3] = r(N)/whtblack[6,1]
summ d_empt if inlist(vble,"tau1") & d_empt<0
matrix whtblack[6,4] = r(N)/whtblack[6,1]
* 

hist d_empt if inlist(vble,"tau2")
summ d_empt if inlist(vble,"tau2"), det
matrix whtblack[7,1] = r(N)
matrix whtblack[7,2] = r(mean)
summ d_empt if inlist(vble,"tau2") & d_empt>0
matrix whtblack[7,3] = r(N)/whtblack[7,1]
summ d_empt if inlist(vble,"tau2") & d_empt<0
matrix whtblack[7,4] = r(N)/whtblack[7,1]
* 

hist d_empt if inlist(vble,"tau3")
summ d_empt if inlist(vble,"tau3"), det
summ d_empt if inlist(vble,"tau3") & d_empt>0
summ d_empt if inlist(vble,"tau3") & d_empt<0
* 

hist d_empt if inlist(vble,"tau4")
summ d_empt if inlist(vble,"tau4"), det
summ d_empt if inlist(vble,"tau4") & d_empt>0
summ d_empt if inlist(vble,"tau4") & d_empt<0
* 

hist d_empt if inlist(vble,"tau5")
summ d_empt if inlist(vble,"tau5"), det
summ d_empt if inlist(vble,"tau5") & d_empt>0
summ d_empt if inlist(vble,"tau5") & d_empt<0
* 

hist d_empt if inlist(vble,"tau6")
summ d_empt if inlist(vble,"tau6"), det
summ d_empt if inlist(vble,"tau6") & d_empt>0
summ d_empt if inlist(vble,"tau6") & d_empt<0
* 
